package com.ly.user_system.exception;

import cn.hutool.core.util.BooleanUtil;
import lombok.Getter;

import java.util.Optional;

@Getter

public enum ExceptionEnums {
    NOT_FIND_DATA(5000,"数据不存在"),

    USER_NOT_FOUND(5001,"用户不存在"),

    USER_HAS_LOCKED(5002,"账号已被锁定"),

    USER_HAS_EXPIRED(5003,"账号已过期"),

    USER_NOT_ENABLED(5004,"用户未启用"),

    ERROR_PASSWORD(5005,"密码错误"),
    ;


    private Integer code;
    private String msg;


    ExceptionEnums(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public <T> T applyObj(T t) {
        return Optional.ofNullable(t).orElseThrow(() -> new LyException(this));
    }



    public void apply(Boolean t) {
        if (BooleanUtil.isFalse(t)) {
            throw new LyException(this);
        }
    }

}
